package com.itheima.demo3;

import java.util.concurrent.locks.ReentrantLock;

public class SellTicket implements Runnable{
    private static int count ;
    private ReentrantLock lock;
    public SellTicket() {
        this.count = 100;
        lock = new ReentrantLock();
    }

    @Override
    public void run() {
        while(true){
            try {
                lock.lock();
                if(count <= 0 )break;

                System.out.println(Thread.currentThread().getName()+"卖出一张票,还剩"+(--count)+"张");
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                lock.unlock();
            }
        }
    }
}
